package com.sxt;

import java.awt.*;

public class Bj {
    //关卡数
    static int level =1;
    //目标得分
    int goal = level *10;
    //总分
    static int count = 0;
    static int waterNum = 3;
    //药水状态 默认false true正在使用
    static boolean waterFlag = false;
    //开始时间
    long startTime;
    //结束时间
    long endTime;
    //药水价格 10以内随机
    int price = (int) (Math.random()*10);
    //是否进入商店 false 不购买
    boolean shop = false;

    //载入图片
    Image bg = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
    Image peo = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
    Image water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");

    //绘制
    void paintSelf(Graphics g) {
        g.drawImage(bg1,0,0,null);
        g.drawImage(bg,0,200,null);
        switch (GameWin.state){
            case 0:
                drawWord(g,80,Color.RED,"点击开始",200,400);
                break;
            case 1:
                g.drawImage(peo,310,50,null);
                drawWord(g,30,Color.BLACK,"积分"+count,30,150);
                //药水
                g.drawImage(water,450,40,null);
                drawWord(g,30,Color.BLACK,"*"+waterNum,510,70);
                //关卡数
                drawWord(g,20,Color.BLACK,"第"+level+"关",30,60);
                //目标积分
                drawWord(g,30,Color.BLACK,"目标:"+goal,30,110);
                //时间组件
                endTime = System.currentTimeMillis();
                Long time = 25 - (endTime - startTime)/1000;
                drawWord(g,30,Color.BLACK,"时间:"+(time>0?time:0),520,150);
                break;
            case 2:
                //药水
                g.drawImage(water,300,400,null);
                drawWord(g,30,Color.BLACK,"价格:"+ price,300,500);
                drawWord(g,30,Color.BLACK,"左键购买 右键跳过"+waterNum,300,600);
                if (shop){
                    count = count - price;
                    waterNum++;
                    shop = false;
                    GameWin.state = 1;
                    startTime = System.currentTimeMillis();
                }
                break;
            case 3:
                drawWord(g,80,Color.RED,"游戏失败",250,350);
                drawWord(g,80,Color.ORANGE,"积分"+count,200,450);
                break;
            case 4:
                drawWord(g,80,Color.RED,"游戏成功",250,350);
                drawWord(g,80,Color.ORANGE,"积分"+count,200,450);
                break;
            default:
        }

    }
    //t倒计时完成 f正在倒计时
    boolean gameTime(){
        long tim=(endTime-startTime)/1000;
        if(tim>25){
            return true;
        }else{
            return false;
        }
    }
    //重置游戏
    void reGame(){
        //关卡数
        level =1;
        //目标得分
        goal = level *10;
        //总分
         count = 0;
        waterNum = 3;
        //药水状态 默认false true正在使用
        waterFlag = false;
    }
    //绘制字符串 积分呢
    public static void drawWord(Graphics g,int size,Color color, String str,int x,int y){
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(str ,x,y);
    }
}
